package org.example.runningforum.modle;

import lombok.Data;
import org.example.runningforum.enums.ResultStatus;

@Data
public class Result <T>{
    private ResultStatus code;
    private String msg;
    private T data;


    public static <T> Result<T> success(){
        Result result = new Result();
        result.setCode(ResultStatus.SUCCESS);
        result.setMsg("欢迎登录");
        return result;
    }

    public static <T> Result<T> success(T data){
        Result result = new Result();
        result.setCode(ResultStatus.SUCCESS);
        result.setMsg("连通中...");
        result.setData(data);
        return result;
    }

    public static <T> Result<T> Fail(T data){
        Result result = new Result();
        result.setCode(ResultStatus.FAIL);
        result.setMsg("连接异常");
        result.setData(null);
        return result;
    }

    public static <T> Result<T> Fail(String message){
        Result result = new Result();
        result.setCode(ResultStatus.FAIL);
        result.setMsg(message);
        result.setData(null);
        return result;
    }

    public static <T> Result<T> unLogin(){
        Result result = new Result();
        result.setCode(ResultStatus.UN_LOGIN);
        result.setMsg("未登录");
        result.setData(null);
        return result;
    }

}
